package com.allwees.bs.module.oms.wf;

import com.baomidou.mybatisplus.core.enums.IEnum;
import com.allwees.core.wf.FsmState;
import com.allwees.core.wf.Transition;
import lombok.Getter;

import java.io.Serializable;
import java.util.Arrays;
import java.util.List;

/**
 * oms 订单 state
 *
 * @author mouhaining
 * @since 2020-01-16 14:31
 */
@Getter
public enum EOmsOrderState implements FsmState<EOmsOrderState, EOmsOrderAction>, IEnum<String>, Serializable {

    START("Start", false, false) {
        @Override
        public List<Transition<EOmsOrderState, EOmsOrderAction>> getTransitions() {
            return Arrays.asList(
                    new Transition<>(EOmsOrderAction.SYSTEM_SYNC, WAIT_MERCHANT_SHIPPING)
            );
        }
    },

    WAIT_MERCHANT_SHIPPING("待发货", true, false) {
        @Override
        public List<Transition<EOmsOrderState, EOmsOrderAction>> getTransitions() {
            return Arrays.asList(
                    new Transition<>(EOmsOrderAction.MERCHANT_ALL_SHIPPED, WAIT_RECEIVE),
                    new Transition<>(EOmsOrderAction.MERCHANT_SHIPPED, MERCHANT_SHIPPING),
                    new Transition<>(EOmsOrderAction.SYSTEM_CLOSE_BY_ALL_REFUND, REFUND)
            );
        }
    },

    MERCHANT_SHIPPING("发货中", true, false) {
        @Override
        public List<Transition<EOmsOrderState, EOmsOrderAction>> getTransitions() {
            return Arrays.asList(
                    new Transition<>(EOmsOrderAction.MERCHANT_ALL_SHIPPED, WAIT_RECEIVE),
                    new Transition<>(EOmsOrderAction.MERCHANT_SHIPPED, MERCHANT_SHIPPING)
            );
        }
    },

    WAIT_RECEIVE("待收货", true, false) {
        @Override
        public List<Transition<EOmsOrderState, EOmsOrderAction>> getTransitions() {
            return Arrays.asList(
                    new Transition<>(EOmsOrderAction.USER_RECEIVED, RECEIVED)
            );
        }
    },

    RECEIVED("已收货", true, false) {
        @Override
        public List<Transition<EOmsOrderState, EOmsOrderAction>> getTransitions() {
            return Arrays.asList(
                    new Transition<>(EOmsOrderAction.SYSTEM_CLOSE_BY_ALL_REFUND, REFUND),
                    new Transition<>(EOmsOrderAction.SYSTEM_JOIN_SETTLE, WAIT_SETTLE)
            );
        }
    },

    WAIT_SETTLE("待结算", true, false) {
        @Override
        public List<Transition<EOmsOrderState, EOmsOrderAction>> getTransitions() {
            return Arrays.asList(
                    new Transition<>(EOmsOrderAction.SYSTEM_AUTO_SETTLED, COMPLETED)
            );
        }
    },

    REFUND("全部退货", false, true),

    CANCELED("Canceled", false, true),

    COMPLETED("已结算", false, true);

    /**
     * 状态描述
     */
    private String desc;

    private boolean started;

    private boolean ended;

    /**
     * 数据库存储用值
     */
    public String key() {
        return name();
    }

    public String desc() {
        return desc;
    }

    @Override
    public boolean started() {
        return started;
    }

    @Override
    public boolean ended() {
        return ended;
    }

    EOmsOrderState(String desc, boolean started, boolean ended) {
        this.desc = desc;
        this.started = started;
        this.ended = ended;
    }

    @Override
    public String getValue() {
        return name();
    }
}
